//
//  TVCellOfFindSolveWay.m
//  LCOnePsychology
//
//  Created by li cheng on 16/8/30.
//  Copyright © 2016年 li cheng. All rights reserved.
//

#import "TVCellOfFindSolveWay.h"
#import "CollectionViewOfFindSolveWay.h"
#import "Masonry.h"
#import "CVCellOfReservationExpert.h"
#import "CVCellOfConfideAndMentoring.h"
#import "OnePsychologyViewController.h"
#import "MainTabBarController.h"
#import "OnePsychologyViewController.h"
@interface TVCellOfFindSolveWay()<UICollectionViewDelegate,UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
@property (weak, nonatomic) IBOutlet UIButton *titleLable;
@property (nonatomic, strong) CollectionViewOfFindSolveWay *collectionViewOfFindSolveWay;
@end
@implementation TVCellOfFindSolveWay
- (instancetype)initWithCoder:(NSCoder *)aDecoder{
    self = [super initWithCoder:aDecoder];
    if (self) {
        // 创建 CollectView
        [self createCollectionView];
    }
    return self;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // 创建 CollectView
        [self createCollectionView];
    }
    return self;
}
#pragma mark - 创建 CollectView
- (void)createCollectionView{
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.minimumLineSpacing = 0;
    layout.minimumInteritemSpacing = 0;
    layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    _collectionViewOfFindSolveWay = [[CollectionViewOfFindSolveWay alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
    _collectionViewOfFindSolveWay.backgroundColor = [UIColor whiteColor];
    _collectionViewOfFindSolveWay.backgroundColor = [UIColor whiteColor];
    _collectionViewOfFindSolveWay.delegate = self;
    _collectionViewOfFindSolveWay.dataSource = self;
    [self.contentView addSubview:_collectionViewOfFindSolveWay];
    [_collectionViewOfFindSolveWay registerNib:[UINib nibWithNibName:@"CVCellOfReservationExpert" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"CVCellOfReservationExpert"];
    [_collectionViewOfFindSolveWay registerNib:[UINib nibWithNibName:@"CVCellOfConfideAndMentoring" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"CVCellOfConfideAndMentoring"];
}
#pragma mark - 重新布局
- (void)layoutSubviews{
    [super layoutSubviews];
    [_collectionViewOfFindSolveWay mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self.contentView).offset(0);
        make.height.mas_offset(self.contentView.bounds.size.height * 4 / 5);
    }];
}
#pragma mark - 代理方法 item 个数的确定
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    return 3;
}
#pragma mark - 代理方法 cell 的赋值
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.item == 0) {
        CVCellOfReservationExpert *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CVCellOfReservationExpert" forIndexPath:indexPath];
        return cell;
    } else if (indexPath.item == 1){
        CVCellOfConfideAndMentoring *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CVCellOfConfideAndMentoring" forIndexPath:indexPath];
        return cell;
    } else {
        CVCellOfConfideAndMentoring *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CVCellOfConfideAndMentoring" forIndexPath:indexPath];
        cell.myImageView.image = [UIImage imageNamed:@"Unknown-5"];
        cell.title.text = @"免费问答";
        cell.describeLabel.text = @"百万网友热心解答";
        return cell;
    }
}
#pragma mark - CollectionViewDelegateFlowLayout 的代理方法 itemSize
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    CGFloat heightFirstItemSize = self.contentView.bounds.size.height * 4 / 5;
    CGFloat widthFirstItemSize = heightFirstItemSize;
    if (indexPath.item != 0) {
        CGSize size = CGSizeMake(_collectionViewOfFindSolveWay.bounds.size.width - widthFirstItemSize, _collectionViewOfFindSolveWay.bounds.size.height / 2);
        return size;
    } else {
        CGSize size = CGSizeMake(widthFirstItemSize, heightFirstItemSize);
        return size;
    }
}
#pragma mark - CollectionView 的点击方法
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    MainTabBarController *mainTabBarController = (MainTabBarController *)self.nextResponder.nextResponder.nextResponder.nextResponder.nextResponder.nextResponder.nextResponder.nextResponder.nextResponder.nextResponder.nextResponder.nextResponder;
    if (indexPath.row == 0) {

        mainTabBarController.selectedIndex = 2;
    }
    if (indexPath.row == 1) {
        [self pleaseWait];
    }
    if (indexPath.row == 2) {
        mainTabBarController.selectedIndex = 1;
    }
}
#pragma mark - 还未开放此功能
- (void)pleaseWait{
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"这个功能目前还没有开放" message:@"你可以尝试别的东西" preferredStyle:UIAlertControllerStyleActionSheet];
    [alertController addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
    }]];
    OnePsychologyViewController *onePsychologyViewController = (OnePsychologyViewController *)self.nextResponder.nextResponder.nextResponder.nextResponder;
    [onePsychologyViewController presentViewController:alertController animated:YES completion:^{
    
    }];
    NSLog(@"%@", self.nextResponder.nextResponder.nextResponder.nextResponder);
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
